#include "gtest/gtest.h"
#include <acapella/thread/thread.h>

using namespace acapella::thread;

int ThreadFunc(void* pParam)
{
    *(int *)pParam = 1000;
    return 0;
}

class ThreadTestClass
{
public:
    int ThreadFunc(void* pParam)
    {
        *(int *)pParam = 2000;
        return 0;
    }
};

TEST(testThread, compileTest)
{
    Thread testThread;

    testThread.SetUserFunction(&ThreadFunc);
    int i = 0;
    testThread.Create(&i, 0);
    testThread.Join(NULL);

    EXPECT_EQ(1000, i);
}

TEST(testThread, normalFunctionTest)
{   
    Thread testThread(&ThreadFunc);

    int i = 0;
    testThread.Create(&i, 0);
    testThread.Join(NULL);

    EXPECT_EQ(1000, i);
}

TEST(testThread, classMethodTest)
{   
    ThreadTestClass t;
    Thread testThread(Thread::functor_type(&t, &ThreadTestClass::ThreadFunc));

    int i = 0;
    testThread.Create(&i, 0);
    testThread.Join(NULL);

    EXPECT_EQ(2000, i);
}
